const express = require('express');
const router = express.Router();
const data = [];

/**
 * @param {Object} options
 * @param {} options.codes
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forPartInvoiceManage', async(req, res, next) => {
    const options = {
        codes: req.query.codes
    };
    const data = {
        message: 'message',
        payload: {
            paymentType: 1
        }
    };
    res.json(data);
});
for(let i = 1; i < 51; i++)
    data.push({
        id: `${i}`,
        code: `XS2019082700-${i}`,
        dealerCode: '10145',
        dealerName: '测试经销商',
        partOrderTypeName: '紧急订单',
        partOrderPriceTerms: 1,
        paymentType: 1,
        status: 1,
        totalQuantity: 50,
        createTime: '2019-08-04T02:37:44.918Z',
        rowVersion: 'string',
        options: [
            'update',
            'abandon',
            'submit',
            'approve',
            'assistUpdate',
            'assistSubmit',
            'create',
        ]
    });
router.get('/forCurrentUser', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: data,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});
const content = [];
for(let i = 1; i < 51; i++)
    content.push({
        id: `${i}`,
        code: `XS2019082700-${i}`,
        status: 1,
        partOrderTypeId: '1',
        partOrderTypeName: '紧急订单',
        partOrderPriceTerms: 1,
        paymentType: 1,
        transportType: 1,
        submitTime: '2019-08-04T02:37:44.918Z',
        dealerCode: '10145',
        dealerName: '测试经销商',
        piCode: 'PI201909040001',
        labelRequirement: 'labelRequirement',
        shippingMark: 'shippingMark',
        isSeparate: true,
        palletizing: 1,
        details: [
            {
                partId: '1',
                partCode: 'partCode1',
                partName: 'partName1',
                planQuantity: 3,
                businessCheck: false,
                dangerousGoods: true,
                airMagneticCheck: false,
                chemicalCheck: true,
            },
            {
                partId: '2',
                partCode: 'partCode2',
                partName: 'partName2',
                planQuantity: 6,
                businessCheck: true,
                dangerousGoods: false,
                airMagneticCheck: true,
                chemicalCheck: false,
            },
            {
                partId: '3',
                partCode: 'partCode3',
                partName: 'partName3',
                planQuantity: 9,
                businessCheck: false,
                dangerousGoods: true,
                airMagneticCheck: true,
                chemicalCheck: false,
            }
        ]
    });
router.get('/forStockRequirement', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

router.get('/forPartOrderPi', (req, res) => {
    const contentforPartOrderPi = [];
    for(let i = 1; i < 51; i++)
        contentforPartOrderPi.push({
            id: `${i}`,
            code: `XS2019082700-${i}`,
            dealerId: 'dealerId111',
            dealerCode: `dealerCode${i}`,
            dealerName: `dealerName${i}`,
            country: `country${i}`,
            status: 1,
            brandId: 'brandId1',
            brandCode: 'brandCode1',
            brandName: 'brandName1',
            customerOrderCode: 'customerOrderCode',
            partOrderTypeId: '1',
            partOrderTypeName: '紧急订单',
            receivedPerson: 'receivedPerson',
            receivedPersonPhone: 'receivedPersonPhone',
            account: 'account',
            receivedAddress: 'receivedAddress',
            receivedPort: 'receivedPort',
            shipmentPort: 'shipmentPort',
            remark: 'remark',
            partOrderPriceTerms: i,
            paymentType: 1,
            transportType: 1,
            totalQuantity: i,
            totalAmount: i * 12.3,
            currency: i,
            submitTime: '2019-08-04T02:37:44.918Z',
            carier: 'carier-string',
        });
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: contentforPartOrderPi,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

router.get('/forPartDataModifyLog', (req, res) => {
    const contentforPartOrderPi = [];
    for(let i = 1; i < 51; i++)
        contentforPartOrderPi.push({
            id: `${i}`,
            code: `XS2019082700-${i}`,
            dealerId: 'dealerId111',
            dealerCode: `dealerCode${i}`,
            dealerName: `dealerName${i}`,
            country: `country${i}`,
            status: 1,
            brandId: 'brandId1',
            brandCode: 'brandCode1',
            brandName: 'brandName1',
            customerOrderCode: 'customerOrderCode',
            partOrderTypeId: '1',
            partOrderTypeName: '紧急订单',
            receivedPerson: 'receivedPerson',
            receivedPersonPhone: 'receivedPersonPhone',
            account: 'account',
            receivedAddress: 'receivedAddress',
            receivedPort: 'receivedPort',
            shipmentPort: 'shipmentPort',
            remark: 'remark',
            partOrderPriceTerms: i,
            paymentType: 1,
            transportType: 1,
            totalQuantity: i,
            totalAmount: i * 12.3,
            currency: i,
            submitTime: '2019-08-04T02:37:44.918Z',
            carier: 'carier-string',
        });
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: contentforPartOrderPi,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});
router.get('/:id/forPartOrderPi', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            id: '1',
            code: 'XS2019082700-1',
            dealerId: 'dealerId111',
            dealerCode: 'dealerCode1',
            dealerName: 'dealerName1',
            country: 'country1',
            status: 1,
            brandId: 'brandId1',
            brandCode: 'brandCode1',
            brandName: 'brandName1',
            customerOrderCode: 'customerOrderCode',
            partOrderTypeId: '1',
            partOrderTypeName: '紧急订单',
            receivedPerson: 'receivedPerson',
            receivedPersonPhone: 'receivedPersonPhone',
            account: 'account',
            receivedAddress: 'receivedAddress',
            receivedPort: 'receivedPort',
            shipmentPort: 'shipmentPort',
            remark: 'remark',
            partOrderPriceTerms: 2,
            paymentType: 1,
            transportType: 1,
            totalQuantity: 12,
            totalAmount: 12.3,
            currency: 1,
            submitTime: '2019-08-04T02:37:44.918Z',
            carier: 'carier-string',
            details: [
                {
                    id: 'detailid1',
                    partId: '1',
                    partCode: 'partCode1',
                    partName: 'partName1',
                    oldPartId: 'oldPartId1',
                    oldPartCode: 'oldPartCode1',
                    oldPartName: 'oldPartName1',
                    quantity: 3,
                    amount: 300,
                    isEstimated: true
                },
                {
                    id: 'detailid2',
                    partId: '2',
                    partCode: 'partCode2',
                    partName: 'partName2',
                    oldPartId: 'oldPartId2',
                    oldPartCode: 'oldPartCode2',
                    oldPartName: 'oldPartName2',
                    quantity: 4,
                    price: 10,
                    amount: 40,
                    isEstimated: false
                },
            ],
            dealerBanks: [
                {
                    id: 'bankid1',
                    code: 'code1',
                    name: 'name1',
                    account: 'account1111',
                },
                {
                    id: 'bankid2',
                    code: 'code2',
                    name: 'name2',
                    account: 'account2222',
                },
            ]
        }
    });
});


router.get('/lastTime', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            id: '1',
            code: 'XS2019082700-1',
            dealerCode: '10145',
            dealerName: '测试经销商',
            partOrderTypeId: '1',
            partOrderTypeName: '紧急订单',
            partOrderPriceTerms: 1,
            paymentType: 1,
            status: 1,
            totalQuantity: 50,
            createTime: '2019-08-04T02:37:44.918Z',
            rowVersion: 'string',
            options: [
                'update',
                'abandon',
                'submit',
                'approve',
                'assistUpdate',
                'assistSubmit',
                'create',
            ],
            partBackOrderCode: 'QH20190827001',
            customerOrderCode: 'KH20190827001',
            dealerId: '1',
            brandId: '1',
            brandCode: 'PBCK',
            brandName: '测试品牌',
            currency: 1,
            country: '外国',
            account: 'ZH25898563215',
            carier: 'carier-string',
            receivedCompany: 'receivedCompany-string',
            receivedTelephone: 'receivedTelephone-string',
            receivedPerson: 'receivedPerson-string',
            receivedPersonPhone: 'receivedPersonPhone-string',
            receivedAddress: 'receivedAddress-string',
            receivedPort: 'receivedPort-string',
            shipmentPort: 'shipmentPort-string',
            requiredArrivedDate: '2018-12-04T02:37:44.918Z',
            transportType: 1,
            remark: 'string'
        }
    });
});

router.get('/export/forCurrentUser', (req, res) => {
    res.json({
        message: '导出成功',
        payload: 'Mock导出'
    });
});
router.put('/:id/abandon', (req, res) => {
    res.json({
        message: '作废成功'
    });
});
router.put('/:id/pass', (req, res) => {
    res.json({
        message: '审核成功'
    });
});
router.put('/:id/reject', (req, res) => {
    res.json({
        message: '驳回成功'
    });
});
router.put('/:id/submit', (req, res) => {
    res.json({
        message: '提交成功'
    });
});
router.put('/:id', (req, res) => {
    res.json({message: '修改成功'});
});
router.post('/', (req, res) => {
    res.json({
        message: '新增成功'
    });
});
router.post('/export/details', (req, res) => {
    res.json({
        message: '成功'
    });
});
router.get('/:id', (req, res) => {
    res.json({
        message: 'ok',
        payload: {
            id: '1',
            code: 'XS2019082700-1',
            dealerCode: '10145',
            dealerName: '测试经销商',
            partOrderTypeId: '1',
            partOrderTypeName: '紧急订单',
            partOrderPriceTerms: 1,
            paymentType: 1,
            status: 1,
            totalQuantity: 50,
            createTime: '2019-08-04T02:37:44.918Z',
            rowVersion: 'string',
            options: [
                'update',
                'abandon',
                'submit',
                'approve',
                'assistUpdate',
                'assistSubmit',
                'create',
            ],
            partBackOrderCode: 'QH20190827001',
            customerOrderCode: 'KH20190827001',
            dealerId: '1',
            brandId: '1',
            brandCode: 'PBCK',
            brandName: '测试品牌',
            currency: 1,
            country: '外国',
            account: 'ZH25898563215',
            carier: 'carier-string',
            receivedCompany: 'receivedCompany-string',
            receivedTelephone: 'receivedTelephone-string',
            receivedPerson: 'receivedPerson-string',
            receivedPersonPhone: 'receivedPersonPhone-string',
            receivedAddress: 'receivedAddress-string',
            receivedPort: 'receivedPort-string',
            shipmentPort: 'shipmentPort-string',
            requiredArrivedDate: '2018-12-04T02:37:44.918Z',
            transportType: 1,
            remark: 'string',
            details: [
                {
                    id: '1',
                    partId: '1',
                    partCode: 'partCode1',
                    partName: 'partName1',
                    oldPartId: '1',
                    oldPartCode: 'oldPartCode1',
                    oldPartName: 'oldPartName1',
                    planQuantity: 3,
                    stockQuantity: 4,
                    approvedQuantity: 5,
                    unit: '个',
                    price: 998,
                    estimatedPrice: 999,
                    minPackSize: 1
                },
                {
                    id: '2',
                    partId: '2',
                    partCode: 'partCode2',
                    partName: 'partName2',
                    oldPartId: '2',
                    oldPartCode: 'oldPartCode2',
                    oldPartName: 'oldPartName2',
                    planQuantity: 3,
                    stockQuantity: 4,
                    approvedQuantity: 5,
                    unit: '个',
                    price: 998,
                    estimatedPrice: 999,
                    minPackSize: 1
                },
                {
                    id: '3',
                    partId: '3',
                    partCode: 'partCode3',
                    partName: 'partName3',
                    oldPartId: '3',
                    oldPartCode: 'oldPartCode3',
                    oldPartName: 'oldPartName3',
                    planQuantity: 3,
                    stockQuantity: 4,
                    approvedQuantity: 5,
                    unit: '个',
                    price: 998,
                    estimatedPrice: 999,
                    minPackSize: 1
                }
            ]
        }
    });
});


module.exports = router;
